var express = require('express');
var router = express.Router();
const {key,secret} = require('../config.js')
// const px = new (require('@msdjl/pxapi'))({apiKey: key, apiSecret: secret});
const getToken = require('../utils/getToken.js')
/* GET home page. */
router.get('/',async function(req, res, next) {
  // const data = await px.offer.all({
  //   offer_type:'sell',
  //   payment_method:'wechat-pay'
  // })
  const token = await getToken()
  console.log(token)
  res.json(token);
});

router.post('/webhook',async function(req, res, next) {
  const spawn = require( 'child_process' ).spawnSync
  const gitpull = spawn( 'git', [ 'pull' ] );
  res.text(`stderr: ${gitpull.stderr.toString()}`)
});

module.exports = router;
